<?php
  header('Content-type: text/html; charset=utf-8');
  error_reporting(E_ALL); 
  date_default_timezone_set("Asia/Saigon");
  require_once("config.php");     
  require_once("functions.php");     
    
  $rows = getSMSLogNotSendMT();
  
  foreach($rows as $row){
       $Phone = $row["mobile"];
       $ServiceNum = $row["serviceNumber"];
       $mo = $row["mo"];
       $Content = $row["mt"];
       $MOId = $row["transactionId"];
       $Charging = $row["status"];
       $RequestId = $row["responseId"];
       $operator = checkTelcoGateWay($Phone);
       
       $mo = trim($mo);
       $mo = preg_replace("/(\s+)/si", " ", $mo);
       $arrMo = explode(" ", $mo);
       $cmdCode= $arrMo[0];
       
        
       $resultSendMT = sendMToGateWay( $ServiceNum,$Phone,$cmdCode,$Content,$MOId,$operator, $Charging,  0);
       $resultSendMT = $resultSendMT == -1?0:1; // 0 Chua gui MT, 1 da gui MT // Nếu chưa gửi dc cần xây kế hoặc để gửi lại
       UpdateSMSLogByMe($row["id"],$Content,$Charging,$resultSendMT,$RequestId); 
        
        echo "MOId=".$MOId."operator=".$operator."ServiceNum=".$ServiceNum."cmdCode=".$cmdCode."Content=".$Content."Phone=".$Phone."Charging=".$Charging."<br>".$resultSendMT."<br>";
  }
?>
